package com.demo.controller;

import com.demo.domain.SysDept;
import com.demo.service.SysDeptService;
import com.demo.utils.AjaxResult;
import com.demo.utils.BaseController;
import com.demo.utils.PageUtils;
import com.demo.utils.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author gxd
 * @since 2025/5/27
 */
@RestController
@RequestMapping("/dept")
@Api(tags = "部门信息")
public class SysDeptController extends BaseController {

    @Autowired
    private SysDeptService deptService;

    @ApiOperation("分页列表-部门列表")
    @PostMapping("/pageList")
    public TableDataInfo pageList(@ApiParam(value = "部门查询条件", required = false) SysDept dept) {
        PageUtils.startPage(dept.getPageNum(), dept.getPageSize());
        List<SysDept> deptList = deptService.pageList(dept);
        return getDataTable(deptList);
    }

    @ApiOperation("不分页列表-部门列表")
    @PostMapping("/list")
    public AjaxResult list(@ApiParam(value = "部门查询条件", required = false) @RequestBody SysDept dept) {
        return success(deptService.selectDeptList(dept));
    }

    @ApiOperation("详情信息-根据Id获取部门详情信息")
    @ApiImplicitParam(name = "id", value = "部门Id", required = true, dataType = "String", paramType = "path")
    @GetMapping("/getById/{id}")
    public AjaxResult getById(@PathVariable(value = "id") String id) {
        return success(deptService.getDeptById(id));
    }

    @ApiOperation("添加或修改-部门信息")
    @PostMapping("/addOrEdit")
    public AjaxResult addOrEdit(@ApiParam(value = "部门实体", required = true) @Valid @RequestBody SysDept dept) {
        return success(deptService.addOrEdit(dept));
    }

    @ApiOperation("删除-部门信息（支持批量）")
    @ApiImplicitParam(name = "ids", value = "部门Id（多个需逗号分隔）", required = true, allowMultiple = true, dataType = "String", paramType = "path")
    @DeleteMapping("/removeById")
    public AjaxResult removeById(@RequestParam(value = "ids") String ids) {
        return toAjax(deptService.batchRemoveById(ids));
    }

    @ApiOperation("树查询-部门树")
    @GetMapping("/getDeptTree")
    public AjaxResult getDeptTree() {
        return success(deptService.getDeptTree());
    }
}
